<?php

use Fisharebest\Webtrees\Functions\FunctionsPrint;
use Fisharebest\Webtrees\Functions\FunctionsPrintFacts;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\View;

?>

<div class="wt-tab-facts py-4">
    <table class="table wt-facts-table">
        <tbody>
            <tr>
                <td colspan="2">
                    <label>
                        <input id="show-relatives-facts" type="checkbox" data-toggle="collapse" data-target=".wt-relation-fact">
                        <?= I18N::translate('Events of close relatives') ?>
                    </label>
                    <?php if ($has_historical_facts) : ?>
                        <label>
                            <input id="show-historical-facts" type="checkbox" data-toggle="collapse" data-target=".wt-historic-fact">
                            <?= I18N::translate('Historic events') ?>
                        </label>
                    <?php endif ?>
                </td>
            </tr>

            <?php foreach ($facts as $fact) : ?>
                <?php FunctionsPrintFacts::printFact($fact, $individual) ?>
            <?php endforeach ?>

            <?php if ($facts->isEmpty()) : ?>
                <tr>
                    <td colspan="2">
                        <?= I18N::translate('There are no facts for this individual.') ?>
                    </td>
                </tr>
            <?php endif ?>

            <?php if ($individual->canEdit()) : ?>
                <?= view('edit/paste-fact-row', ['record' => $individual, 'facts' => $clipboard_facts]) ?>

                <?php FunctionsPrint::printAddNewFact($individual, $facts, Individual::RECORD_TYPE) ?>
            <?php endif ?>
        </tbody>
    </table>
</div>

<?php View::push('javascript') ?>
<script>
  'use strict';

  webtrees.persistentToggle('show-relatives-facts');
  webtrees.persistentToggle('show-historical-facts');
</script>
<?php View::endpush() ?>
